package com.example.controller;

import com.example.entity.CommonResult;
import com.example.entity.Dept;
import com.example.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author: 21050134
 * @date: 2023/10/13 14:12
 * @description:
 */
@RestController
@Slf4j
public class DeptController {

	@Autowired
	private DeptService deptService;

	@Value("${server.port}")
	private String serverPort;

	@RequestMapping(value = "/dept/get/{id}",method = RequestMethod.GET)
	public CommonResult<Dept> get(@PathVariable("id") Integer id){
		log.info("端口："+serverPort+ "\t + dept/get/");
		try{
			TimeUnit.SECONDS.sleep(1);
			log.info("休眠1秒");
		}catch (InterruptedException e){
			e.printStackTrace();
		}
		Dept dept =  deptService.get(id);
		CommonResult<Dept> result = new CommonResult<>(200,"from mysql,serverPort :"+ serverPort,dept);
		return result;
	}

	@RequestMapping(value = "/dept/list",method = RequestMethod.GET)
	public CommonResult<List<Dept>> list(){
		log.info("端口："+serverPort+ "\t + dept/list/");
		List<Dept> depts = deptService.selectAll();
		CommonResult<List<Dept>> result = new CommonResult<>(200,"from mysql,serverPort :"+ serverPort,depts);
		return result;
	}

}
